package top.lixunda.commerce.common.core.controller.wrapper;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sun.istack.internal.NotNull;

/**
 * @author LiXunda
 * @version time:2019/10/16 17:04
 */
@SuppressWarnings({"WeakerAccess", "unused"})
public class PageWrapper<T> {

    private Page<T> page;

    private BaseDataQuerySqlWrapper<T> wrapper;

    public PageWrapper() {
    }

    public PageWrapper(@NotNull Page<T> page, @NotNull BaseDataQuerySqlWrapper<T> wrapper) {
        this.page = page;
        this.wrapper = wrapper;
    }

    public PageWrapper(@NotNull Page<T> page, @NotNull IQuerySqlWrapper<T> wrapper) {
        this(page, wrapper.toDataQuerySqlWrapper());
    }

    public PageWrapper(long current, long size, @NotNull BaseDataQuerySqlWrapper<T> wrapper) {
        this(new Page<>(current, size), wrapper);
    }

    public PageWrapper(long current, long size, @NotNull IQuerySqlWrapper<T> wrapper) {
        this(new Page<>(current, size), wrapper.toDataQuerySqlWrapper());
    }

    public static <T> PageWrapper<T> get(@NotNull Page<T> page, @NotNull BaseDataQuerySqlWrapper<T> wrapper) {
        return new PageWrapper<>(page, wrapper);
    }

    public static <T> PageWrapper<T> get(@NotNull Page<T> page, @NotNull IQuerySqlWrapper<T> wrapper) {
        return new PageWrapper<>(page, wrapper);
    }

    public static <T> PageWrapper<T> get(long current, long size, @NotNull BaseDataQuerySqlWrapper<T> wrapper) {
        return new PageWrapper<>(current, size, wrapper);
    }

    public static <T> PageWrapper<T> get(long current, long size, @NotNull IQuerySqlWrapper<T> wrapper) {
        return new PageWrapper<>(current, size, wrapper);
    }

    public Page<T> getPage() {
        return page;
    }

    public PageWrapper<T> setPage(Page<T> page) {
        this.page = page;
        return this;
    }

    public BaseDataQuerySqlWrapper<T> getWrapper() {
        return wrapper;
    }

    public PageWrapper<T> setWrapper(BaseDataQuerySqlWrapper<T> wrapper) {
        this.wrapper = wrapper;
        return this;
    }

    public PageWrapper<T> setPage(long current, long size) {
        if (page == null) {
            page = new Page<>(current, size);
        } else {
            page.setCurrent(current).setSize(size);
        }
        return this;
    }

    public PageWrapper<T> setCurrent(long current) {
        if (page == null) {
            page = new Page<>();
        }
        page.setCurrent(current);
        return this;
    }

    public PageWrapper<T> setSize(long size) {
        if (page == null) {
            page = new Page<>();
        }
        page.setSize(size);
        return this;
    }

}
